<?php

if (isset($_GET['key']) and PregKey($_GET['key'])) {
    $t_data = array(
        "username" => NULL,
        "password" => NULL,
        "port"     => NULL,
        "mail"     => NULL);
    
    $Confirm = ConfirmTry($GL, $_GET['key'], $t_data); 
    
    if ($Confirm == "yes") {
        Logger($LogFile, "END REGISTRATION (".$t_data["username"].")");
    
        $Mail = str_replace("{MOUNT}", "http://".$SITE.":".$t_data["port"]."/live", file_get_contents("mail2.tpl", FILE_USE_INCLUDE_PATH));
        $Mail = str_replace("{LINK}", "http://".$SITE, $Mail);
        $Mail = str_replace("{LOGIN}", $t_data["username"], $Mail);
        $Mail = str_replace("{PASSWORD}", $t_data["password"], $Mail);
        SendMail($GL, $t_data["mail"], $Mail);

        $_SESSION['LOGIN_OK'] = TRUE;
        $_SESSION['LOGIN_NAME'] = $t_data["username"];

        Logger($LogFile, "ACCEPT LOGIN (".$t_data["username"].")");
        header("Location: http://" . $SITE . "/?action=actok");
    }
    elseif ($Confirm == "no") {
        Logger($LogFile, "FAILED REGISTRATION CONFIRM");
        $BODY = "Некорректная ссылка активации.";
    }
    else {
        Logger($LogFile, "FAILED REGISTRATION CONFIRM");
        header("Location: http://" . $SITE . "/?action=error");
    }
}
else
    $BODY = "<span>Некорректная ссылка активации.</span>";

?>
